package com.mark.mall.admin.platform.controller;


import com.github.pagehelper.PageInfo;
import com.mark.mall.admin.platform.dto.PageParamDTO;
import com.mark.mall.admin.platform.dto.UserDTO;
import com.mark.mall.admin.platform.dto.param.RegisterParam;
import com.mark.mall.admin.platform.dto.param.UserUpdateParam;
import com.mark.mall.admin.platform.entity.User;
import com.mark.mall.admin.platform.service.UserService;
import com.mark.mall.common.resultBean.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 管理员表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-02-28
 */
@RestController
@RequestMapping("/admin/user")
@Api(tags = "后台管理用户模块")
@RequiredArgsConstructor
public class UserController {
    private final UserService userService;

    @ApiOperation("后台用户列表")
    @GetMapping("adminUserPageInfo")
    public R<PageInfo<UserDTO>> adminUserPageInfo(PageParamDTO param) {
        return userService.adminUserPageInfo(param);
    }

    @ApiOperation("后台用户注册")
    @PostMapping("register")
    public R<Boolean> register(@RequestBody @Valid RegisterParam param) {
        return userService.register(param.getUserName(), param.getPassword());
    }

    @ApiOperation("后台用户修改")
    @PostMapping("update")
    public R<Boolean> update(@RequestBody @Valid UserUpdateParam param) {
        return userService.updateUser(param);
    }

    @ApiOperation("查找全部用户接口-自定义sql注入")
    @GetMapping("findAll")
    public R<List<User>> findAll(){return userService.findAll();}

}
